package binderon.com.bo.transformer.imp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import binderon.com.bo.transformer.BeanTransformer;

public abstract class BaseBoToModelTransformerImp implements BeanTransformer {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List transform(List source) throws Exception{
		List result = null;
		if (source != null && !source.isEmpty()) {
			result = new ArrayList();
			Iterator sourceIterator = source.iterator();
			while (sourceIterator.hasNext()) {				
				result.add(transform(sourceIterator.next()));
			}
		}
		return result;
	}
	public Object transform(Object source) throws Exception  {
		Object target = getBoBean();
		BeanUtils.copyProperties( target,source);
		return target;
	}
	
	protected abstract Object getBoBean();

}
